import Page from './page'
import { kWinHints } from './api'
import { showLogin } from './utils'

const Main = Page.extend(function () {
  var self = this

  var initPage = function () {
    self.removeStyle(kWinHints.kTopMostHint)
    self.addStyle(kWinHints.kResizableHint)
    self.addStyle(kWinHints.kInTaskbarHint)
    self.hide()
    self.resize(1248, 780)
    // self.setMinSize(1248, 780)
    self.align(4)
    self.setNCBorderWidth(2)
    self.setCaptionArea([[0, 0, 1248 - 120, 30]])
    if (typeof window !== 'undefined') {
      window.oncontextmenu = function (event) {
        event.returnValue = false
      }
      window.ondragstart = function (event) {
        return false
      }
      window.addEventListener('resize', function () {
        self.setCaptionArea([[0, 0, window.innerWidth - 120, 30]])
      })
    }
  }

  this.init = function () {
    this.super.init()
    if (!self.isLogined()) {
      showLogin()
      return
    }
    initPage()
  }

  this.start = function (vue) {
    this.super.start(vue)
    self.show()
  }
})

var _main = null

Main.impl = function () {
  return _main || (_main = new Main())
}

export default Main
